package com.pliu.sqlSession;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.pliu.config.XMLConfigBuilder;
import com.pliu.pojo.Configuration;

import javax.sql.DataSource;
import java.io.InputStream;

/**
 * @ClassName SqlSessionFactoryBuilder
 * @Description 解析配置文件,生成SqlSessionFactory
 * @Author pliu
 * @Date 2020/6/21 10:03
 * @Version 1.0
 **/
public class SqlSessionFactoryBuilder {
    /**
     * 首先，使用dom4j解析配置文件，将解析出来的内容封装到容器对象中；
     * 然后，创建SqlSessionFactory对象，用来生产SqlSession会话对象（工厂模式）
     * @param in
     * @return
     */
    public SqlSessionFactory build(InputStream in) throws Exception {
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);

        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }
}
